using UnityEngine;
using UnityEditor;
using AudioStudio;

[CustomPropertyDrawer(typeof(SoundParam))]
public class SoundParamDrawer : PropertyDrawer
{
    private static GUIContent EventContent = new GUIContent("Event");
    private static GUIContent StopContent = new GUIContent("Stop");
    private static GUIContent TransitionDurationContent = new GUIContent("Fade");

    private static float LineHeight = 20f;

    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        return LineHeight;
    }

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        int oldIndentLevel = EditorGUI.indentLevel;
        label = EditorGUI.BeginProperty(position, label, property);
        Rect contentPosition = EditorGUI.PrefixLabel(position, label);

        EditorGUI.indentLevel = 0;

        float contentWidth = contentPosition.width;

        Rect area = contentPosition;
        area.height = LineHeight;
        EditorGUIUtility.labelWidth = 40;

        area.width = contentWidth * 0.6f;
        EditorGUI.PropertyField(area, property.FindPropertyRelative("audioEvent"), EventContent);

        area.x += area.width;
        area.width = contentWidth * 0.2f;
        EditorGUI.PropertyField(area, property.FindPropertyRelative("stop"), StopContent);

        area.x += area.width;
        area.width = contentWidth * 0.2f;
        EditorGUI.PropertyField(area, property.FindPropertyRelative("transitionDuration"), TransitionDurationContent);

        EditorGUI.EndProperty();
        EditorGUI.indentLevel = oldIndentLevel;
    }
}